<?php
/**
* Real Estate Projects Collection Save
*/
    if (!defined("EXPONENT")) exit("");
    $subject = null;		
    if (isset($_POST['id'])) {
        $subject = $db->selectObject('duan_collections', 'id='.intval($_POST['id']));
        if ($subject != null) {
            $loc = unserialize($subject->location_data);
        }
    } else {
        // No rank in this section
        $subject->rank = $db->max('duan_collections', 'rank', null, "location_data='".serialize($loc)."'");
        if ($subject->rank == null) {
            $subject->rank = 0;
        } else { 
            $subject->rank += 1;
        }
    }

    //if (exponent_permissions_check("manage",$loc)) {	
    if ((exponent_users_isAdmin() || exponent_permissions_check("administrate",$loc))
         && exponent_users_isLoggedIn()) {

        $subject= duan_duan::collections_update($_POST, $subject);
        $subject->location_data = serialize($loc);
        if (isset($subject->id)) {
            // calculate all song length
            $db->updateObject($subject,"duan_collections");
        } else {
            $subject->id = $db->insertObject($subject,"duan_collections");
        }		
        //
        exponent_flow_redirect(SYS_FLOW_ACTION);
        //redirect_to($url);
    } else {
        echo SITE_403_HTML;
    }


?>
